package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.alibaba.druid.support.json.JSONUtils;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class Region extends BaseDomain {
    public static final int STATE_NORMAL = 0;//状态普通
    public static final int STATE_HOT = 1;//状态推荐


    private String name;//名字

    private Long parentId;//父级ID

    private Integer state=0;//状态

    /**
     * 转为按照规则的方法
     *
     * @return
     */
    public Map<String, Object> toMap() {
        Map<String, Object> map = new HashMap<>();
        //把对象都转化为map直接扔过去
        map.put("id", getId());
        map.put("text", name);
        //在页面上显示加号
        map.put("lazyLoad",true);
        String[] s = new String[]{"推荐"};
        if (state != null && state == STATE_HOT) {
            map.put("tags", s);
        }
            map.put("parentId", parentId);
            map.put("json",getJsonString());

        return map;
    }
    //把数据转化为json
    public String getJsonString(){
        HashMap<String,Object> map= new HashMap<>();
        map.put("id",getId());
        map.put("name",name);
        map.put("parentId",parentId);
        if (state!=null&&state==1){
            map.put("state",1);

        }else {
        map.put("state",0);
        }
        return JSONUtil.toJSONString(map);
    }

}